'use strict';
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const db = uniCloud.database({});
	const shop = db.collection('db_shop_bag')
	let dd;
	await shop.where({
		item_id: event.con,
		uid: event.uid,
		type: -1
	}).get().then((res) => {
		dd = res.data
	})
	if (dd.length > 0) {
		shop.where({
			item_id: event.con
		}).update({
			count: dd[0].count + event.count
		}).then((res) => {
			return res
		})
	} else {
		shop.add({
			item_id: event.con,
			count: event.count,
			uid: event.uid,
			type: -1
		}).then((res) => {
			return res
		})
	}

	//返回数据给客户端
	return event
};